package 力扣;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author yyq
 * @create 2022-03-13 19:58
 */
public class leetcode349 {
    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> num1=new HashSet<>();
        Set<Integer> num2=new HashSet<>();
        Set<Integer> equal=new HashSet<>();
        for (int i = 0; i < nums1.length; i++) {
            num1.add(nums1[i]);
        }
        for (int i = 0; i < nums2.length; i++) {
            num2.add(nums2[i]);
        }
        Iterator<Integer> iterator = num1.iterator();
        while (iterator.hasNext()){
            int a= iterator.next();
            if(num2.contains(a)) equal.add(a);
        }
        int[] nums=new int[equal.size()];
        int i=0;
        for (Integer integer : equal) {
            nums[i]=integer;
            i++;
        }

        return nums;
    }
}
